<!-- 面试安排 -->
<script>
import HPCommonPage from "@/components/HPCommonPage";
import HPTable from "@/components/HPTable";
import { arrangementTableColumn } from "../js/cloumn";
import { interviewArrangementStatus } from "../js/status";
import { approverOption } from "@/views/interviewManagement/js/status";
import HPDialog from "@/components/HPDialog";
import InterviewDetailArrangeInp from "@/components/detailCommons/interviewDetailArrangeInp";
import { enitInterviewTime } from "@/fetch/modules/arrange";
import getQuery from '@/utils/mixins/getQuery';

function fetchInterViewLists(store, opts) {
  return store.dispatch("GET_INTER_VIEW_LISTS", opts);
}

export default {
  mixins: [getQuery],
  created() {
    const { stus } = this.$route.query;
    if (stus) {
      this.selectData.status = stus;
    }
    this.fetchTableData();
    if (stus) {
      this.$router.push({ query: {} });
    }
  },
  methods: {
    // * 获取列表数据
    async fetchTableData() {
      this.isLoad = true;
      await fetchInterViewLists(this.$store, this.selectData);
      this.isLoad = false;
      const { state, data } = this.$store.getters.getArrangeLists;
      if (state === "0000") {
        const { list = [], total, lastPage, pageNum } = data || {};
        this.tableData = list.map(item => {
          return {
            ...item,
            interviewTimeSup: item.interviewTimeSup === '1971-01-01 00:00:00'? '':item.interviewTimeSup
          }
        });
        if(pageNum > lastPage && lastPage > 0) {
          this.selectData.pageCurrent = lastPage
          this.fetchTableData()
        }
        this.totals = total;
      }
    },
    // * 查询
    onSearch() {
      this.selectData.pageCurrent = 1;
      this.searchData = { ...this.selectData }
      this.fetchTableData();
    },
    // * 查看
    onLookDetail({ needsCvId, state, interview_num, closeState }) {
      this.$router.push({
        path: `/arrange/detail/${needsCvId}`,
        query: {
          stus: state,
          num: interview_num,
          formQuery: JSON.stringify(this.searchData),
          closeState,
        },
      });
    },
    // 取消面试
    // * 查看
    onCencel({ needsCvId, state, interview_num, }) {
      this.$router.push({
        path: `/arrange/detail/${needsCvId}`,
        query: { stus: state, num: interview_num, cancel: 1 },
      });
    },
    editInterviewTime(row) {
      this.visible = true
      this.interviewId = row.interviewId + ""

      this.needsCvId = row.needsCvId;
      this.isCloseNeeds = row.state === 6;
      if (row.interviewTime) {
        this.interTime = row.interviewTime
      }
    },
    onCloseDialog() {
      console.log('onCloseDialog')
      this.visible = false
    },
    onSubmit(val) {
      const params = {
        id: this.interviewId,
        interviewTime: val.tempTime,
        remarks: val.desc,

      }
      // console.log(val, params)

      enitInterviewTime(params).then(res => {
        if(res.data.state === '0000') {
          this.$message({
            message: res.data.message,
            type: 'success',
            duration: 1500,
          });
          this.fetchTableData()
          this.onCloseDialog()
        }
      })
    },
    onConfirmDialog() {},
    // * 切换页条数
    handleSizeChange(val) {
      this.selectData.pageSize = val;
      this.searchData = { ...this.selectData }
      this.onSearch();
    },
    // * 切换页数
    handleCurrentChange(val) {
      this.selectData.pageCurrent = val;
      this.searchData = { ...this.selectData }
      this.fetchTableData();
    },
  },
  data() {
    return {
      selectData: {
        // * 条件查询对象
        needsCode: "",
        postCode: "",
        name: "",
        status: "",
        pageCurrent: 1,
        pageSize: 10,
      },
      tabsList: interviewArrangementStatus,
      tableHeaderItems: arrangementTableColumn,
      approverStatus: approverOption,
      tableData: [],
      isLoad: false,
      totals: 0,
      visible: false,
      interviewId: null,
      needsCvId: null,
      interTime: null,
      isCloseNeeds: false,
    };
  },
  components: {
    HPCommonPage,
    HPTable,
    HPDialog,
    InterviewDetailArrangeInp
  },
};
</script>

<template>
  <HPCommonPage :titleText="'面试管理 / 面试安排'">
    <template v-slot:searchForm>
      <el-form :inline="true" :model="selectData" class="form-box res-form-box">
        <el-form-item label="需求单号：">
          <el-input
            v-model="selectData.needsCode"
            clearable
            placeholder="请输入需求单号"
          ></el-input>
        </el-form-item>
        <el-form-item label="岗位名称：">
          <el-input
            v-model="selectData.postCode"
            clearable
            placeholder="请输入岗位名称"
          ></el-input>
        </el-form-item>
        <el-form-item label="姓名：">
          <el-input
            v-model="selectData.name"
            clearable
            placeholder="请输入姓名"
          ></el-input>
        </el-form-item>
        <el-form-item label="状态：">
          <el-select
            v-model="selectData.status"
            placeholder="请选择状态"
            clearable=""
          >
            <template v-for="item in tabsList">
              <el-option
                v-if="!item.hidden"
                :key="item.key"
                :label="item.label"
                :value="item.key"
              >
              </el-option>
            </template>
          </el-select>
        </el-form-item>
        <!-- <el-form-item label="审批状态：">
          <el-select
            v-model="selectData.approvalState"
            placeholder="请选择安排审批状态"
            clearable=""
          >
            <el-option
              v-for="item in approverStatus"
              :key="item.key"
              :label="item.label"
              :value="item.key"
            >
            </el-option>
          </el-select>
        </el-form-item> -->
      </el-form>
    </template>
    <template v-slot:searchFormbtn>
      <el-button type="success" size="small" @click="onSearch">查询</el-button>
    </template>
    <template v-slot:table>
      <HPTable
        :tableHeaderItems="tableHeaderItems"
        :tableData="tableData"
        :loading="isLoad"
      >
      </HPTable>
    </template>
    <template v-slot:pagination>
      <el-pagination
        v-if="totals"
        @size-change="handleSizeChange"
        @current-change="handleCurrentChange"
        :current-page="selectData.pageCurrent"
        :page-sizes="[10, 20, 30, 40, 50]"
        :page-size="selectData.pageSize"
        background
        layout="total, sizes, prev, pager, next, jumper"
        :total="totals"
      >
      </el-pagination>
    </template>
     <HPDialog
      width="1200px"
      :confirmBtnText="'保存'"
      :title="`调整候选人面试时间`"
      :visible.sync="visible"
      :footer="false"
      :footerClassName="'text-center'"
      :before-close="onCloseDialog"
      :destroy-on-close="true"
      @close-dialog="onCloseDialog"
      @confirm-dialog="onConfirmDialog"
    >
      <template v-slot:body>
        <InterviewDetailArrangeInp
          :interview-id="interviewId"
          :interview-time="interTime"
          :needs-cv-id="needsCvId"
          :is-close-needs="isCloseNeeds"
          :title-visiable="false"
          :on-submit="onSubmit"
        ></InterviewDetailArrangeInp>
      </template>
    </HPDialog>
  </HPCommonPage>
</template>

<style lang="scss"></style>
